home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / atarifb.c < prev    next >
C/C++ Source or Header  |  2000-05-04  |  11KB  |  419 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12. /* local */
  13. size_t atarifb_alphap1_vram_size;
  14. size_t atarifb_alphap2_vram_size;
  15. unsigned char *atarifb_alphap1_vram;
  16. unsigned char *atarifb_alphap2_vram;
  17. unsigned char *atarifb_scroll_register;
  18. unsigned char *alphap1_dirtybuffer;
  19. unsigned char *alphap2_dirtybuffer;
  20.  
  21. extern int atarifb_game;
  22.  
  23. WRITE_HANDLER( atarifb_alphap1_vram_w );
  24. WRITE_HANDLER( atarifb_alphap2_vram_w );
  25. WRITE_HANDLER( atarifb_scroll_w );
  26. void atarifb_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh);
  27.  
  28. struct rectangle bigfield_area = {  4*8, 34*8-1, 0*8, 32*8-1 };
  29. struct rectangle left_area =     {  0*8,  3*8-1, 0*8, 32*8-1 };
  30. struct rectangle right_area =    { 34*8, 38*8-1, 0*8, 32*8-1 };
  31.  
  32. /***************************************************************************
  33. ***************************************************************************/
  34. WRITE_HANDLER( atarifb_alphap1_vram_w )
  35. {
  36.     if (atarifb_alphap1_vram[offset] != data)
  37.     {
  38.         atarifb_alphap1_vram[offset] = data;
  39.  
  40.         alphap1_dirtybuffer[offset] = 1;
  41.     }
  42. }
  43.  
  44. WRITE_HANDLER( atarifb_alphap2_vram_w )
  45. {
  46.     if (atarifb_alphap2_vram[offset] != data)
  47.     {
  48.         atarifb_alphap2_vram[offset] = data;
  49.  
  50.         alphap2_dirtybuffer[offset] = 1;
  51.     }
  52. }
  53.  
  54. /***************************************************************************
  55. ***************************************************************************/
  56. WRITE_HANDLER( atarifb_scroll_w )
  57. {
  58.     if (data - 8 != *atarifb_scroll_register)
  59.     {
  60.         *atarifb_scroll_register = data - 8;
  61.         memset(dirtybuffer,1,videoram_size);
  62.     }
  63. }
  64.  
  65. /***************************************************************************
  66. ***************************************************************************/
  67.  
  68. int atarifb_vh_start(void)
  69. {
  70.     if (generic_vh_start()!=0)
  71.         return 1;
  72.  
  73.     alphap1_dirtybuffer = malloc (atarifb_alphap1_vram_size);
  74.     alphap2_dirtybuffer = malloc (atarifb_alphap2_vram_size);
  75.     if ((!alphap1_dirtybuffer) || (!alphap2_dirtybuffer))
  76.     {
  77.         generic_vh_stop();
  78.         return 1;
  79.     }
  80.  
  81.     memset(alphap1_dirtybuffer, 1, atarifb_alphap1_vram_size);
  82.     memset(alphap2_dirtybuffer, 1, atarifb_alphap2_vram_size);
  83.     memset(dirtybuffer, 1, videoram_size);
  84.  
  85.     return 0;
  86. }
  87.  
  88. /***************************************************************************
  89. ***************************************************************************/
  90.  
  91. void atarifb_vh_stop(void)
  92. {
  93.     generic_vh_stop();
  94.     free (alphap1_dirtybuffer);
  95.     free (alphap2_dirtybuffer);
  96. }
  97.  
  98.  
  99. /***************************************************************************
  100.  
  101.   Draw the game screen in the given osd_bitmap.
  102.   Do NOT call osd_update_display() from this function, it will be called by
  103.   the main emulation engine.
  104.  
  105. ***************************************************************************/
  106. void atarifb_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  107. {
  108.     int offs,obj;
  109.     int sprite_bank;
  110.  
  111.     if (full_refresh)
  112.     {
  113.         memset(alphap1_dirtybuffer, 1, atarifb_alphap1_vram_size);
  114.         memset(alphap2_dirtybuffer, 1, atarifb_alphap2_vram_size);
  115.         memset(dirtybuffer,1,videoram_size);
  116.     }
  117.  
  118.     /* Soccer uses a different graphics set for sprites */
  119.     if (atarifb_game == 4)
  120.         sprite_bank = 2;
  121.     else
  122.         sprite_bank = 1;
  123.  
  124.     /* for every character in the Player 1 Video RAM, check if it has been modified */
  125.     /* since last time and update it accordingly. */
  126.     for (offs = atarifb_alphap1_vram_size - 1;offs >= 0;offs--)
  127.     {
  128.         if (alphap1_dirtybuffer[offs])
  129.         {
  130.             int charcode;
  131.             int flipbit;
  132.             int disable;
  133.             int sx,sy;
  134.  
  135.             alphap1_dirtybuffer[offs] = 0;
  136.  
  137.             sx = 8 * (offs / 32) + 35*8;
  138.             sy = 8 * (offs % 32) + 8;
  139.  
  140.             charcode = atarifb_alphap1_vram[offs] & 0x3f;
  141.             flipbit = (atarifb_alphap1_vram[offs] & 0x40) >> 6;
  142.             disable = (atarifb_alphap1_vram[offs] & 0x80) >> 7;
  143.  
  144.             if (!disable)
  145.             {
  146.                 drawgfx(bitmap,Machine->gfx[0],
  147.                     charcode, 0,
  148.                     flipbit,flipbit,sx,sy,
  149.                     &right_area,TRANSPARENCY_NONE,0);
  150.             }
  151.         }
  152.     }
  153.  
  154.     /* for every character in the Player 2 Video RAM, check if it has been modified */
  155.     /* since last time and update it accordingly. */
  156.     for (offs = atarifb_alphap2_vram_size - 1;offs >= 0;offs--)
  157.     {
  158.         if (alphap2_dirtybuffer[offs])
  159.         {
  160.             int charcode;
  161.             int flipbit;
  162.             int disable;
  163.             int sx,sy;
  164.  
  165.             alphap2_dirtybuffer[offs] = 0;
  166.  
  167.             sx = 8 * (offs / 32);
  168.             sy = 8 * (offs % 32) + 8;
  169.  
  170.             charcode = atarifb_alphap2_vram[offs] & 0x3f;
  171.             flipbit = (atarifb_alphap2_vram[offs] & 0x40) >> 6;
  172.             disable = (atarifb_alphap2_vram[offs] & 0x80) >> 7;
  173.  
  174.             if (!disable)
  175.             {
  176.                 drawgfx(bitmap,Machine->gfx[0],
  177.                     charcode, 0,
  178.                     flipbit,flipbit,sx,sy,
  179.                     &left_area,TRANSPARENCY_NONE,0);
  180.             }
  181.         }
  182.     }
  183.  
  184.     /* for every character in the Video RAM, check if it has been modified */
  185.     /* since last time and update it accordingly. */
  186.     for (offs = videoram_size - 1;offs >= 0;offs--)
  187.     {
  188.         if (dirtybuffer[offs])
  189.         {
  190.             int charcode;
  191.             int flipx,flipy;
  192.             int sx,sy;
  193.  
  194.             dirtybuffer[offs]=0;
  195.  
  196.             charcode = videoram[offs] & 0x3f;
  197.             flipx = (videoram[offs] & 0x40) >> 6;
  198.             flipy = (videoram[offs] & 0x80) >> 7;
  199.  
  200.             sx = (8 * (offs % 32) - *atarifb_scroll_register);
  201.             sy = 8 * (offs / 32) + 8;
  202.  
  203.             /* Soccer hack */
  204.             if (atarifb_game == 4)
  205.             {
  206.                 sy += 8;
  207.             }
  208.  
  209.             /* Baseball hack */
  210.             if (atarifb_game == 0x03) sx -= 8;
  211.  
  212.             if (sx < 0) sx += 256;
  213.             if (sx > 255) sx -= 256;
  214.  
  215.             drawgfx(tmpbitmap,Machine->gfx[1],
  216.                     charcode, 0,
  217.                     flipx,flipy,sx,sy,
  218.                     0,TRANSPARENCY_NONE,0);
  219.         }
  220.     }
  221.  
  222.     /* copy the character mapped graphics */
  223.     copybitmap(bitmap,tmpbitmap,0,0,8*3,0,&bigfield_area,TRANSPARENCY_NONE,0);
  224.  
  225.     /* Draw our motion objects */
  226.     for (obj=0;obj<16;obj++)
  227.     {
  228.         int charcode;
  229.         int flipx,flipy;
  230.         int sx,sy;
  231.         int shade = 0;
  232.  
  233.         sy = 255 - spriteram[obj*2 + 1];
  234.         if (sy == 255) continue;
  235.  
  236.         charcode = spriteram[obj*2] & 0x3f;
  237.         flipx = (spriteram[obj*2] & 0x40);
  238.         flipy = (spriteram[obj*2] & 0x80);
  239.         sx = spriteram[obj*2 + 0x20] + 8*3;
  240.  
  241.         /* Note on Atari Soccer: */
  242.         /* There are 3 sets of 2 bits each, where the 2 bits represent */
  243.         /* black, dk grey, grey and white. I think the 3 sets determine the */
  244.         /* color of each bit in the sprite, but I haven't implemented it that way. */
  245.         if (atarifb_game == 4)
  246.         {
  247.             shade = ((spriteram[obj*2+1 + 0x20]) & 0x07);
  248.  
  249.             drawgfx(bitmap,Machine->gfx[sprite_bank+1],
  250.                 charcode, shade,
  251.                 flipx,flipy,sx,sy,
  252.                 &bigfield_area,TRANSPARENCY_PEN,0);
  253.  
  254.             shade = ((spriteram[obj*2+1 + 0x20]) & 0x08) >> 3;
  255.         }
  256.  
  257.         drawgfx(bitmap,Machine->gfx[sprite_bank],
  258.                 charcode, shade,
  259.                 flipx,flipy,sx,sy,
  260.                 &bigfield_area,TRANSPARENCY_PEN,0);
  261.  
  262.         /* If this isn't soccer, handle the multiplexed sprites */
  263.         if (atarifb_game != 4)
  264.         {
  265.             /* The down markers are multiplexed by altering the y location during */
  266.             /* mid-screen. We'll fake it by essentially doing the same thing here. */
  267.             if ((charcode == 0x11) && (sy == 0x07))
  268.             {
  269.                 sy = 0xf1; /* When multiplexed, it's 0x10...why? */
  270.                 drawgfx(bitmap,Machine->gfx[sprite_bank],
  271.                     charcode, 0,
  272.                     flipx,flipy,sx,sy,
  273.                     &bigfield_area,TRANSPARENCY_PEN,0);
  274.             }
  275.         }
  276.     }
  277.  
  278. /* If this isn't Soccer, print the plays at the top of the screen */
  279. if (atarifb_game != 4)
  280. {
  281.     int x;
  282.     char buf1[25], buf2[25];
  283. extern int atarifb_lamp1, atarifb_lamp2;
  284.  
  285.     switch (atarifb_game)
  286.     {
  287.         case 0x01: /* 2-player football */
  288.             switch (atarifb_lamp1)
  289.             {
  290.                 case 0x00:
  291.                     sprintf (buf1, "                    ");
  292.                     break;
  293.                 case 0x01:
  294.                     sprintf (buf1, "SWEEP               ");
  295.                     break;
  296.                 case 0x02:
  297.                     sprintf (buf1, "KEEPER              ");
  298.                     break;
  299.                 case 0x04:
  300.                     sprintf (buf1, "BOMB                ");
  301.                     break;
  302.                 case 0x08:
  303.                     sprintf (buf1, "DOWN & OUT          ");
  304.                     break;
  305.             }
  306.             switch (atarifb_lamp2)
  307.             {
  308.                 case 0x00:
  309.                     sprintf (buf2, "                    ");
  310.                     break;
  311.                 case 0x01:
  312.                     sprintf (buf2, "SWEEP               ");
  313.                     break;
  314.                 case 0x02:
  315.                     sprintf (buf2, "KEEPER              ");
  316.                     break;
  317.                 case 0x04:
  318.                     sprintf (buf2, "BOMB                ");
  319.                     break;
  320.                 case 0x08:
  321.                     sprintf (buf2, "DOWN & OUT          ");
  322.                     break;
  323.             }
  324.             break;
  325.         case 0x02: /* 4-player football */
  326.             switch (atarifb_lamp1 & 0x1f)
  327.             {
  328.                 case 0x01:
  329.                     sprintf (buf1, "SLANT OUT           ");
  330.                     break;
  331.                 case 0x02:
  332.                     sprintf (buf1, "SLANT IN            ");
  333.                     break;
  334.                 case 0x04:
  335.                     sprintf (buf1, "BOMB                ");
  336.                     break;
  337.                 case 0x08:
  338.                     sprintf (buf1, "DOWN & OUT          ");
  339.                     break;
  340.                 case 0x10:
  341.                     sprintf (buf1, "KICK                ");
  342.                     break;
  343.                 default:
  344.                     sprintf (buf1, "                    ");
  345.                     break;
  346.             }
  347.             switch (atarifb_lamp2 & 0x1f)
  348.             {
  349.                 case 0x01:
  350.                     sprintf (buf2, "SLANT OUT           ");
  351.                     break;
  352.                 case 0x02:
  353.                     sprintf (buf2, "SLANT IN            ");
  354.                     break;
  355.                 case 0x04:
  356.                     sprintf (buf2, "BOMB                ");
  357.                     break;
  358.                 case 0x08:
  359.                     sprintf (buf2, "DOWN & OUT          ");
  360.                     break;
  361.                 case 0x10:
  362.                     sprintf (buf2, "KICK                ");
  363.                     break;
  364.                 default:
  365.                     sprintf (buf2, "                    ");
  366.                     break;
  367.             }
  368.             break;
  369.         case 0x03: /* 2-player baseball */
  370.             switch (atarifb_lamp1 & 0x0f)
  371.             {
  372.                 case 0x01:
  373.                     sprintf (buf1, "RT SWING/FASTBALL   ");
  374.                     break;
  375.                 case 0x02:
  376.                     sprintf (buf1, "LT SWING/CHANGE-UP  ");
  377.                     break;
  378.                 case 0x04:
  379.                     sprintf (buf1, "RT BUNT/CURVE BALL  ");
  380.                     break;
  381.                 case 0x08:
  382.                     sprintf (buf1, "LT BUNT/KNUCKLE BALL");
  383.                     break;
  384.                 default:
  385.                     sprintf (buf1, "                    ");
  386.                     break;
  387.             }
  388.             switch (atarifb_lamp2 & 0x0f)
  389.             {
  390.                 case 0x01:
  391.                     sprintf (buf2, "RT SWING/FASTBALL   ");
  392.                     break;
  393.                 case 0x02:
  394.                     sprintf (buf2, "LT SWING/CHANGE-UP  ");
  395.                     break;
  396.                 case 0x04:
  397.                     sprintf (buf2, "RT BUNT/CURVE BALL  ");
  398.                     break;
  399.                 case 0x08:
  400.                     sprintf (buf2, "LT BUNT/KNUCKLE BALL");
  401.                     break;
  402.                 default:
  403.                     sprintf (buf2, "                    ");
  404.                     break;
  405.             }
  406.             break;
  407.         default:
  408.             sprintf (buf1, "                    ");
  409.             sprintf (buf2, "                    ");
  410.             break;
  411.     }
  412.     for (x = 0;x < 20;x++)
  413.             drawgfx(bitmap,Machine->uifont,buf1[x],UI_COLOR_NORMAL,0,0,6*x + 24*8,0,0,TRANSPARENCY_NONE,0);
  414.  
  415.     for (x = 0;x < 20;x++)
  416.             drawgfx(bitmap,Machine->uifont,buf2[x],UI_COLOR_NORMAL,0,0,6*x,0,0,TRANSPARENCY_NONE,0);
  417. }
  418. }
  419.